﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:ui="clr-namespace:System.Windows.Documents;assembly=PresentationUI"
             		xmlns:platform="clr-namespace:WindowsPlatform">

    <Style x:Key="FlatProgressBar" TargetType="{x:Type ProgressBar}">
    	<Setter Property="Background" Value="Transparent"/>
    	<Setter Property="Foreground" Value="{Binding Path=(platform:Styles.StatusBarProgressBackgroundBrush), Mode=OneWay}"/>
    	<Setter Property="BorderBrush" Value="{Binding Path=(platform:Styles.StatusBarProgressBorderBrush), Mode=OneWay}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ProgressBar">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" BorderThickness="0" CornerRadius="0" Padding="0">
                        <Grid x:Name="PART_Track">
                            <Rectangle x:Name="PART_Indicator" HorizontalAlignment="Left" Fill="{TemplateBinding Foreground}" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter"/>
    <Geometry x:Key="DownArrow"> M 0,0 L 3.5,4 L 7,0 Z</Geometry>
    <Geometry x:Key="UpArrow">   M 0,4 L 3.5,0 L 7,4 Z</Geometry>
    <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry>
    <Geometry x:Key="Checkmark">F1 M 10.0,1.2 L 4.7,9.1 L 4.5,9.1 L 0,5.2 L 1.3,3.5 L 4.3,6.1L 8.3,0 L 10.0,1.2 Z</Geometry>

    <Style TargetType="{x:Type Menu}">
        <Setter Property="FontFamily" Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}"/>
        <Setter Property="FontSize" Value="{DynamicResource {x:Static SystemFonts.MenuFontSizeKey}}"/>
        <Setter Property="FontStyle" Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}"/>
        <Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Menu}">
                    <Border 
                        Background="{Binding Path=(platform:Styles.MenuBarBackgroundBrush), Mode=OneWay}"
                        BorderBrush="{Binding Path=(platform:Styles.MenuBarBorderBrush), Mode=OneWay}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Padding="{TemplateBinding Padding}" 
                        SnapsToDevicePixels="true"
                        TextElement.Foreground="{Binding Path=(platform:Styles.MenuBarForegroundBrush), Mode=OneWay}">
                        <ItemsPresenter 
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="MenuScrollButton" TargetType="{x:Type RepeatButton}" BasedOn="{x:Null}" >
        <Setter Property="ClickMode" Value="Hover"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border x:Name="templateRoot"
                        SnapsToDevicePixels="true"
                        Background="Transparent"
                        BorderBrush="Transparent"
                        BorderThickness="1">
                        <ContentPresenter
                            Margin="6"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type FrameworkElement}, ResourceId=MenuScrollViewer}" TargetType="{x:Type ScrollViewer}" BasedOn="{x:Null}">
        <Setter Property="HorizontalScrollBarVisibility" Value="Hidden"/>
        <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Border
                            Grid.Column="0"
                            Grid.Row="1">
                            <ScrollContentPresenter
                                Margin="{TemplateBinding Padding}"
                                CanContentScroll="{TemplateBinding CanContentScroll}"/>
                        </Border>
                        <RepeatButton
                            Grid.Column="0"
                            Grid.Row="0"
                            Style="{StaticResource MenuScrollButton}"
                            Command="{x:Static ScrollBar.LineUpCommand}"
                            CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                            Focusable="false">
                            <RepeatButton.Visibility>
                                <MultiBinding ConverterParameter="0" Converter="{StaticResource MenuScrollingVisibilityConverter}" FallbackValue="Visibility.Collapsed">
                                    <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/>
                                    <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/>
                                    <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
                                    <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
                                </MultiBinding>
                            </RepeatButton.Visibility>
                            <Path
                                Data="{StaticResource UpArrow}"
                                Fill="{Binding Path=(platform:Styles.MenuForegroundBrush), Mode=OneWay}" />
                        </RepeatButton>
                        <RepeatButton
                            Grid.Column="0"
                            Grid.Row="2"
                            Style="{StaticResource MenuScrollButton}"
                            Command="{x:Static ScrollBar.LineDownCommand}"
                            CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                            Focusable="false">
                            <RepeatButton.Visibility>
                                <MultiBinding ConverterParameter="100" Converter="{StaticResource MenuScrollingVisibilityConverter}" FallbackValue="Visibility.Collapsed">
                                    <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/>
                                    <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/>
                                    <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
                                    <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
                                </MultiBinding>
                            </RepeatButton.Visibility>
                            <Path
                                Data="{StaticResource DownArrow}"
                                Fill="{Binding Path=(platform:Styles.MenuForegroundBrush), Mode=OneWay}" />
                        </RepeatButton>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
        <Setter Property="MinHeight" Value="1"/>
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Separator}">
                    <Border Background="{Binding Path=(platform:Styles.MenuSeparatorBrush), Mode=OneWay}"
                            BorderBrush="{Binding Path=(platform:Styles.MenuSeparatorBrush), Mode=OneWay}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Margin="30,0,0,0"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type MenuItem}, ResourceId=TopLevelItemTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="templateRoot"
            SnapsToDevicePixels="true"
            BorderThickness="{TemplateBinding BorderThickness}"
            Background="Transparent"
            BorderBrush="Transparent"
            TextElement.Foreground="{Binding Path=(platform:Styles.MenuBarForegroundBrush), Mode=OneWay}">
            <Grid VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="Icon"
                    ContentSource="Icon"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Width="16"
                    Height="16"
                    Margin="3" />
                <Path x:Name="GlyphPanel"
                    Data="{StaticResource Checkmark}"
                    FlowDirection="LeftToRight"
                    Margin="3"
                    Visibility="Collapsed"
                    VerticalAlignment="Center"
                    Fill="{Binding Path=(platform:Styles.MenuBarForegroundBrush), Mode=OneWay}" />
                <ContentPresenter
                    Grid.Column="1"
                    ContentSource="Header"
                    RecognizesAccessKey="True"
                    Margin="{TemplateBinding Padding}"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible"/>
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="templateRoot" Property="Background" Value="{Binding Path=(platform:Styles.MenuHighlightBackgroundBrush), Mode=OneWay}" />
                <Setter TargetName="templateRoot" Property="BorderBrush" Value="{Binding Path=(platform:Styles.MenuHighlightBorderBrush), Mode=OneWay}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{Binding Path=(platform:Styles.MenuDisabledForegroundBrush), Mode=OneWay}" />
                <Setter TargetName="GlyphPanel" Property="Fill" Value="{Binding Path=(platform:Styles.MenuDisabledForegroundBrush), Mode=OneWay}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type MenuItem}, ResourceId=TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="templateRoot"
            SnapsToDevicePixels="true"
            BorderThickness="{TemplateBinding BorderThickness}"
            Background="Transparent"
            BorderBrush="Transparent"
            TextElement.Foreground="{Binding Path=(platform:Styles.MenuBarForegroundBrush), Mode=OneWay}">
            <Grid VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="Icon"
                    ContentSource="Icon"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Width="16"
                    Height="16"
                    Margin="3"/>
                <Path x:Name="GlyphPanel"
                    Data="{StaticResource Checkmark}"
                    FlowDirection="LeftToRight"
                    Margin="3"
                    Visibility="Collapsed"
                    VerticalAlignment="Center"
                    Fill="{Binding Path=(platform:Styles.MenuBarForegroundBrush), Mode=OneWay}" />
                <ContentPresenter
                    Grid.Column="1"
                    ContentSource="Header"
                    RecognizesAccessKey="True"
                    Margin="{TemplateBinding MenuItem.Padding}"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                <Popup x:Name="PART_Popup"
                    AllowsTransparency="true"
                    Focusable="false"
                    IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
                    PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                    Placement="Bottom"
                    PlacementTarget="{Binding ElementName=templateRoot}" >
                    <Border x:Name="SubMenuBorder"
                        Background="{Binding Path=(platform:Styles.MenuBackgroundBrush), Mode=OneWay}"
                        BorderBrush="{Binding Path=(platform:Styles.MenuBorderBrush), Mode=OneWay}"
                        BorderThickness="1"
                        Padding="2">
                        <ScrollViewer x:Name="SubMenuScrollViewer"
                            Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                            <Grid RenderOptions.ClearTypeHint="Enabled">
                                <Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
                                    <Rectangle
                                        Name="OpaqueRect"
                                        Height="{Binding ElementName=SubMenuBorder,Path=ActualHeight}"
                                        Width="{Binding ElementName=SubMenuBorder,Path=ActualWidth}"
                                        Fill="{Binding ElementName=SubMenuBorder,Path=Background}" />
                                </Canvas>
                                <Rectangle HorizontalAlignment="Left"
                                           Width="1"
                                           Margin="29,2,0,2"
                                           Fill="{Binding Path=(platform:Styles.MenuSeparatorBrush), Mode=OneWay}"/>
                                <ItemsPresenter x:Name="ItemsPresenter"
                                    KeyboardNavigation.DirectionalNavigation="Cycle"
                                    KeyboardNavigation.TabNavigation="Cycle"
                                    Grid.IsSharedSizeScope="true"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </Grid>
                        </ScrollViewer>
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None"/>
            </Trigger>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible"/>
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="templateRoot" Property="Background" Value="{Binding Path=(platform:Styles.MenuBarHighlightBackgroundBrush), Mode=OneWay}" />
                <Setter TargetName="templateRoot" Property="BorderBrush" Value="{Binding Path=(platform:Styles.MenuBarHighlightBorderBrush), Mode=OneWay}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{Binding Path=(platform:Styles.MenuDisabledForegroundBrush), Mode=OneWay}" />
                <Setter TargetName="GlyphPanel" Property="Fill" Value="{Binding Path=(platform:Styles.MenuDisabledForegroundBrush), Mode=OneWay}" />
            </Trigger>
            <Trigger SourceName="SubMenuScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false" >
                <Setter TargetName="OpaqueRect"  Property="Canvas.Top"  Value="{Binding ElementName=SubMenuScrollViewer, Path=VerticalOffset}" />
                <Setter TargetName="OpaqueRect" Property="Canvas.Left" Value="{Binding ElementName=SubMenuScrollViewer, Path=HorizontalOffset}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type MenuItem}, ResourceId=SubmenuItemTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="templateRoot"
            SnapsToDevicePixels="true"
            Height="22"
            BorderThickness="{TemplateBinding BorderThickness}"
            Background="Transparent"
            BorderBrush="Transparent"
            TextElement.Foreground="{Binding Path=(platform:Styles.MenuForegroundBrush), Mode=OneWay}">
            <Grid Margin="-1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="22" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
                    <ColumnDefinition Width="13"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
                    <ColumnDefinition Width="20"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="Icon"
                    ContentSource="Icon"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Width="16"
                    Height="16"
                    Margin="6,3"/>
                <Border x:Name="GlyphPanel"
                    Visibility="Hidden"
                    Height="22"
                    Width="22"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Background="{Binding Path=(platform:Styles.MenuSelectedBackgroundBrush), Mode=OneWay}"
                    BorderBrush="{Binding Path=(platform:Styles.MenuSelectedBorderBrush), Mode=OneWay}"
                    BorderThickness="1"
                    ClipToBounds="False"
                    Margin="-1,0,0,0">
                    <Path x:Name="Glyph"
                        Data="{StaticResource Checkmark}"
                        FlowDirection="LeftToRight"
                        Height="11"
                        Width="10"
                        Fill="{Binding Path=(platform:Styles.MenuForegroundBrush), Mode=OneWay}" />
                </Border>
                <ContentPresenter x:Name="menuHeaderContainer"
                    Grid.Column="2"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    ContentSource="Header"
                    RecognizesAccessKey="True"
                    Margin="0,0,0,1"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                <TextBlock x:Name="menuGestureText"
                    Grid.Column="4"
                    Text="{TemplateBinding InputGestureText}"
                    Margin="{TemplateBinding MenuItem.Padding}"
                    VerticalAlignment="Center"
                    Opacity="0.7" />
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible"/>
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="templateRoot" Property="Background" Value="{Binding Path=(platform:Styles.MenuHighlightBackgroundBrush), Mode=OneWay}" />
                <Setter TargetName="templateRoot" Property="BorderBrush" Value="{Binding Path=(platform:Styles.MenuHighlightBorderBrush), Mode=OneWay}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{Binding Path=(platform:Styles.MenuDisabledForegroundBrush), Mode=OneWay}" />
                <Setter TargetName="Glyph" Property="Fill" Value="{Binding Path=(platform:Styles.MenuDisabledForegroundBrush), Mode=OneWay}" />
            </Trigger>        
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type MenuItem}, ResourceId=SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="templateRoot"
            SnapsToDevicePixels="true"
            Height="22"
            BorderThickness="{TemplateBinding BorderThickness}"
            Background="Transparent"
            BorderBrush="Transparent"
            TextElement.Foreground="{Binding Path=(platform:Styles.MenuForegroundBrush), Mode=OneWay}">
            <Grid Margin="-1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="22" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
                    <ColumnDefinition Width="13"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
                    <ColumnDefinition Width="20"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="Icon"
                    ContentSource="Icon"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Width="16"
                    Height="16"
                    Margin="6,3"/>
                <Border x:Name="GlyphPanel"
                    BorderThickness="1"
                    Height="22"
                    Width="22"
                    Visibility="Hidden"
                    VerticalAlignment="Center"
                    Margin="-1,0,0,0"
                    BorderBrush="{Binding Path=(platform:Styles.MenuHighlightBorderBrush), Mode=OneWay}"
                    Background="{Binding Path=(platform:Styles.MenuHighlightBackgroundBrush), Mode=OneWay}">
                    <Path x:Name="Glyph"
                        Data="{DynamicResource Checkmark}"
                        FlowDirection="LeftToRight"
                        Height="11"
                        Width="9"
                        Fill="{Binding Path=(platform:Styles.MenuForegroundBrush), Mode=OneWay}" />
                </Border>
                <ContentPresenter
                    Grid.Column="2"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    ContentSource="Header"
                    RecognizesAccessKey="True"
                    Margin="0,0,0,1"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                <TextBlock
                    Grid.Column="4"
                    Text="{TemplateBinding InputGestureText}"
                    VerticalAlignment="Center"
                    Margin="0,0,0,1"
                    Opacity="0.7" />
                <Path x:Name="RightArrow"
                    Grid.Column="5"
                    Data="{StaticResource RightArrow}"
                    Margin="10,0,0,0"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Left"
                    Fill="{Binding Path=(platform:Styles.MenuForegroundBrush), Mode=OneWay}" />
                <Popup x:Name="PART_Popup"
                    AllowsTransparency="true"
                    Focusable="false"
                    IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
                    PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                    Placement="Right"
                    HorizontalOffset="-2"
                    VerticalOffset="-3">
                    <Border x:Name="SubMenuBorder"
                        Background="{Binding Path=(platform:Styles.MenuBackgroundBrush), Mode=OneWay}"
                        BorderBrush="{Binding Path=(platform:Styles.MenuBorderBrush), Mode=OneWay}"
                        BorderThickness="1"
                        Padding="2">
                        <ScrollViewer x:Name="SubMenuScrollViewer"
                            Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                            <Grid RenderOptions.ClearTypeHint="Enabled">
                                <Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
                                    <Rectangle
                                        Name="OpaqueRect"
                                        Height="{Binding ElementName=SubMenuBorder,Path=ActualHeight}"
                                        Width="{Binding ElementName=SubMenuBorder,Path=ActualWidth}"
                                        Fill="{Binding ElementName=SubMenuBorder,Path=Background}" />
                                </Canvas>
                                <Rectangle HorizontalAlignment="Left"
                                           Width="1"
                                           Margin="29,0,0,0"
                                           Fill="{Binding Path=(platform:Styles.MenuSeparatorBrush), Mode=OneWay}"/>
                                <ItemsPresenter x:Name="ItemsPresenter"
                                    KeyboardNavigation.DirectionalNavigation="Cycle"
                                    KeyboardNavigation.TabNavigation="Cycle"
                                    Grid.IsSharedSizeScope="true"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </Grid>
                        </ScrollViewer>
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None"/>
            </Trigger>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible"/>
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="templateRoot" Property="Background" Value="{Binding Path=(platform:Styles.MenuHighlightBackgroundBrush), Mode=OneWay}" />
                <Setter TargetName="templateRoot" Property="BorderBrush" Value="{Binding Path=(platform:Styles.MenuHighlightBorderBrush), Mode=OneWay}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{Binding Path=(platform:Styles.MenuDisabledForegroundBrush), Mode=OneWay}" />
                <Setter TargetName="Glyph" Property="Fill" Value="{Binding Path=(platform:Styles.MenuDisabledForegroundBrush), Mode=OneWay}" />
                <Setter TargetName="RightArrow" Property="Fill" Value="{Binding Path=(platform:Styles.MenuDisabledForegroundBrush), Mode=OneWay}" />
            </Trigger>
            <Trigger SourceName="SubMenuScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false" >
                <Setter TargetName="OpaqueRect" Property="Canvas.Top" Value="{Binding ElementName=SubMenuScrollViewer, Path=VerticalOffset}" />
                <Setter TargetName="OpaqueRect" Property="Canvas.Left" Value="{Binding ElementName=SubMenuScrollViewer, Path=HorizontalOffset}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}">
        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type MenuItem}, ResourceId=SubmenuItemTemplateKey}}" />
        <Style.Triggers>
            <Trigger Property="Role" Value="TopLevelHeader">
                <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type MenuItem}, ResourceId=TopLevelHeaderTemplateKey}}" />
                <Setter Property="Padding" Value="6,0"/>
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
                <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type MenuItem}, ResourceId=TopLevelItemTemplateKey}}" />
                <Setter Property="Padding" Value="6,0"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
                <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type MenuItem}, ResourceId=SubmenuHeaderTemplateKey}}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="{x:Type ContextMenu}" TargetType="{x:Type ContextMenu}">
        <Setter Property="FontFamily"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}"/>
        <Setter Property="FontSize"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontSizeKey}}"/>
        <Setter Property="FontStyle"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}"/>
        <Setter Property="FontWeight"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}"/>
        <Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"/>
        <Setter Property="VerticalContentAlignment"
                Value="Center"/>
        <Setter Property="BorderThickness"
                Value="1"/>
        <Setter Property="Padding"
                Value="2"/>
        <Setter Property="Grid.IsSharedSizeScope"
                Value="true"/>
        <Setter Property="HasDropShadow"
                Value="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"/>
        <Setter Property="ScrollViewer.PanningMode"
                Value="Both"/>
        <Setter Property="Stylus.IsFlicksEnabled"
                Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContextMenu}">
                    <Border Name="ContextMenuBorder" Background="{Binding Path=(platform:Styles.MenuBackgroundBrush), Mode=OneWay}"
                            BorderBrush="{Binding Path=(platform:Styles.MenuBorderBrush), Mode=OneWay}"
                            BorderThickness="{TemplateBinding BorderThickness}"
            				TextElement.Foreground="{Binding Path=(platform:Styles.MenuForegroundBrush), Mode=OneWay}">
                        <ScrollViewer Name="ContextMenuScrollViewer"
                                      Grid.ColumnSpan="2" Margin="1,0"
                                      Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type FrameworkElement}, ResourceId=MenuScrollViewer}}">
                          <Grid RenderOptions.ClearTypeHint="Enabled">
                            <Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
                                <Rectangle
                                    Name="OpaqueRect"
                                    Height="{Binding ElementName=ContextMenuBorder,Path=ActualHeight}"
                                    Width="{Binding ElementName=ContextMenuBorder,Path=ActualWidth}"
                                    Fill="{Binding ElementName=ContextMenuBorder,Path=Background}" />
                            </Canvas>
                            <Rectangle Fill="{Binding Path=(platform:Styles.MenuBackgroundBrush), Mode=OneWay}"
                                       HorizontalAlignment="Left"
                                       Width="28"
                                       Margin="1,2"
                                       RadiusX="2"
                                       RadiusY="2"/>
                            <!--<Rectangle HorizontalAlignment="Left"
                                       Width="1"
                                       Margin="29,2,0,2"
                                       Fill="{Binding Path=(platform:Styles.MenuSeparatorBrush), Mode=OneWay}"/>-->
                            <ItemsPresenter Name="ItemsPresenter" Margin="{TemplateBinding Padding}"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                          </Grid>
                        </ScrollViewer>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="ContextMenuScrollViewer"
                                 Property="ScrollViewer.CanContentScroll"
                                 Value="false" >
                            <Setter TargetName="OpaqueRect"
                                    Property="Canvas.Top"
                                    Value="{Binding ElementName=ContextMenuScrollViewer, Path=VerticalOffset}" />
                            <Setter TargetName="OpaqueRect"
                                    Property="Canvas.Left"
                                    Value="{Binding ElementName=ContextMenuScrollViewer, Path=HorizontalOffset}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
        <Setter Property="Background" Value="{Binding Path=(platform:Styles.TooltipBackgroundBrush), Mode=OneWay}" />
        <Setter Property="BorderBrush" Value="{Binding Path=(platform:Styles.TooltipBorderBrush), Mode=OneWay}" />
        <Setter Property="Foreground" Value="{Binding Path=(platform:Styles.TooltipTextBrush), Mode=OneWay}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Padding" Value="6,4" />
        <Setter Property="FontFamily" Value="{DynamicResource {x:Static SystemFonts.StatusFontFamilyKey}}"/>
        <Setter Property="FontSize" Value="{DynamicResource {x:Static SystemFonts.StatusFontSizeKey}}"/>
        <Setter Property="FontStyle" Value="{DynamicResource {x:Static SystemFonts.StatusFontStyleKey}}"/>
        <Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.StatusFontWeightKey}}"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="HasDropShadow" Value="False" />
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" />
        <Setter Property="SnapsToDevicePixels" Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToolTip">
                    <Border Name="Border" 
                        Background="{TemplateBinding Background}" 
                        BorderBrush="{TemplateBinding BorderBrush}" 
                        BorderThickness="{TemplateBinding BorderThickness}" 
                        SnapsToDevicePixels="True">
                        <ContentPresenter 
                            Margin="{TemplateBinding Padding}" 
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>